import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'

// 导入全局样式表
import "./assets/css/global.css";
// 导入字体图标
import "./assets/fonts/iconfont.css";

// 导入NProgress
import NProgress from "nprogress";
import "nprogress/nprogress.css";

import axios from "axios";
// axios.defaults.baseURL = "http://www.tangxiaoyang.vip:8888/api/private/v1/";
axios.defaults.baseURL = "http://39.104.96.29:8801/api/private/v1/";

// 拦截所有的请求，为请求头添加token验证
axios.interceptors.request.use((config) => {
  //在request拦截器中，展示进度条NProgress.start();
  NProgress.start();
  config.headers.Authorization = sessionStorage.getItem("token");
  return config;
}, error => {
  // Do something with request error
  console.log(error) // for debug
  Promise.reject(error)
});
axios.interceptors.response.use((config) => {
  //在response拦截器中，展示进度条NProgress.done();
  NProgress.done();
  return config;
}, error => {
  // Do something with request error
  console.log(error) // for debug
});


Vue.prototype.$http = axios;

// 全局过滤器
Vue.filter("dateFormat", function (dateStr) {
  //得到特定的时间
  // var date = new Date(dateStr * 1000).toISOString().substring(0, 10);
  var date = new Date(parseInt(dateStr) * 1000);
  var year = date.getFullYear();
  //ES6语法填充：var month = (date.getMonth()+1).toString().padStart(2, '0');
  var month =
    date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1;
  var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  var hh = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  var mm = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  var ss = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  return `${year}-${month}-${day} ${hh}:${mm}:${ss}`;
});

// 全局注册第三方表格组件
import ZkTable from "vue-table-with-tree-grid";
Vue.component("tree-table", ZkTable);

// 全局安装富文本编辑器
import VueQuillEditor from "vue-quill-editor";
import "quill/dist/quill.core.css"; // import styles
import "quill/dist/quill.snow.css"; // for snow theme
import "quill/dist/quill.bubble.css"; // for bubble theme
Vue.use(VueQuillEditor /* { default global options } */);

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
